package edu.xmut.yuepaibackend.handler;

import edu.xmut.yuepaibackend.utils.BizException;
import edu.xmut.yuepaibackend.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {


    @ExceptionHandler(BizException.class)
    public R handleException(BizException e) {
        log.error("业务异常，{}", e.getMessage());
        return R.fail(500, e.getMessage());
    }


    @ExceptionHandler(Exception.class)
    public R handleException(Exception e) {
        log.error("系统异常，{}", e.getMessage());
        e.printStackTrace();
        return R.fail(500, "系统异常，联系管理员");
    }
}
